<script>
import Vue from 'vue'
import { log } from 'util'
export default {
	onLaunch: function (option) {
		Vue.prototype.deviceUuid = 'not'
		// 小程序为分享页打开 获取分享的item
		if (option && option.query.type === 'share') {
			if (!Vue.prototype.shareItem) Vue.prototype.shareItem = option.query.item
		} else {
			const query = option.query
			let sceneString = []
			for (let key in query) {
				sceneString.push(key + '=' + query[key])
			}
			sceneString = sceneString.join('&')
		}
		//获取deviceUuid
		uni.login({
			success: (res) => {
				console.log(res);
				let json = {}
				// #ifdef MP-WEIXIN
				json = {
					mpType: 'WEIXIN',
					code: res.code,
					sceneString: this.sceneString,
				}
				// #endif
				this.$post(this.api.getDeviceUuid, json).then((data) => {
					console.log(data)
					Vue.prototype.deviceUuid = data.deviceUuid
					Vue.prototype.hasMerchant = data.hasMerchant
					Vue.prototype.hasExpert = data.hasExpert
					Vue.prototype.merchant = data.merchant
					Vue.prototype.hasOfficial = data.hasOfficial
					Vue.prototype.sessionKey = data.sessionKey
					if (data.neededToChooseMerchant) {
						this.$Router.replace({ name: 'chooseMerchant' })
					}
				})
			},
		})
		this.$post(this.api.getProfile, {}).then((data) => {
			Vue.prototype.about = data.about
			Vue.prototype.correctAudioUrls = data.correctAudioUrls
			Vue.prototype.incorrectAudioUrls = data.incorrectAudioUrls
			Vue.prototype.isQuestionSortRandom = data.isQuestionSortRandom
			Vue.prototype.merchantProtocol = data.merchantProtocol
			Vue.prototype.courseTags = data.courseTags
		})
	},
	onShow: function () {
		//小程序更新
		return
		const updateManager = uni.getUpdateManager()
		updateManager.onCheckForUpdate(function (res) {
			if (res.hasUpdate) {
				updateManager.onUpdateReady(function (res) {
					uni.showModal({
						title: '更新提示',
						content: '新版本已经准备好，是否重启应用？',
						success(res) {
							if (res.confirm) {
								// 新的版本已经下载好
								updateManager.applyUpdate()
							}
						},
					})
				})
				updateManager.onUpdateFailed(function (res) {
					// 新的版本下载失败
					uni.showToast({
						title: '网络异常',
						icon: 'loading',
						duration: 2000,
					})
				})
			}
		})
	},
}
</script>

<style lang="scss">
@import 'uview-ui/index.scss';
.img {
	height: 0;
	display: block;
	width: 100%;
	height: auto;
}
page {
	background-color: #fed46b;
}
.outIn {
	animation: outIn 600ms;
	animation-fill-mode: forwards;
}
.touch {
	transform: scale(0.9) !important;
}
@font-face {
	font-family: 'heziWord';
	src: url('https://hz-huibenxia.oss-cn-shenzhen.aliyuncs.com/ttf/ttf.woff');
}

.fonts {
	font-family: 'heziWord';
}
@keyframes outIn {
	0% {
		opacity: 0;
		transform: scale(0.9);
	}
	100% {
		opacity: 1;
		transform: scale(1);
	}
}
</style>
